package com.zz.parkingsystem.service.impl;

import com.zz.parkingsystem.entity.Parking;
import com.zz.parkingsystem.entity.Section;
import com.zz.parkingsystem.entity.Strategy;
import com.zz.parkingsystem.mapper.ParkingMapper;
import com.zz.parkingsystem.mapper.SectionMapper;
import com.zz.parkingsystem.mapper.StrategyMapper;
import com.zz.parkingsystem.service.ParkingService;
import com.zz.parkingsystem.vo.ParkingVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ParkingServiceImpl implements ParkingService {
    @Autowired
    private ParkingMapper parkingMapper;
    @Autowired
    private SectionMapper sectionMapper;
    @Autowired
    private StrategyMapper strategyMapper;
    @Override
    public int deleteByPrimaryKey(Long id) {
        return parkingMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Parking record) {
        return parkingMapper.insert(record);
    }

    @Override
    public int insertSelective(Parking record) {
        return parkingMapper.insertSelective(record);
    }

    @Override
    public Parking selectByPrimaryKey(Long id) {
        return parkingMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Parking record) {
        return parkingMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Parking record) {
        return parkingMapper.updateByPrimaryKey(record);
    }

    @Override
    public ParkingVO selParkingVOByPkNo(String pkno) {
        ParkingVO parkingVO = new ParkingVO();
        Parking parking = parkingMapper.selParkingByPkno(pkno);
        Integer secId = parking.getSecId();
        Section section = sectionMapper.selectByPrimaryKey(secId.longValue());
        Strategy strategy = strategyMapper.selectByPrimaryKey(section.getStagyId().longValue());
        parkingVO.setParking(parking);
        parkingVO.setSection(section);
        parkingVO.setStrategy(strategy);
        return parkingVO;
    }
}
